﻿
@{
    ViewBag.title = "index";
    Layout = "/Views/Shared/_Layout_iframe.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>EditPrice</title>
</head>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改商品零售价</legend>
    </fieldset>
    <form class="layui-form" lay-filter="productform">
        <div class="layui-form-item">
            <label class="layui-form-label">零售价</label>
            <div class="layui-input-inline">
                <input type="text" name="Price" lay-verify="required" placeholder="零售价" autocomplete="off" class="layui-input">
            </div>
        </div>
        <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" style="margin-left:50px;">提交</button>
        <input type="hidden" name="Id" id="hfid" value="@ViewBag.Id" />
    </form>
    <script>
        var table;
        layui.use(['table', 'form', 'layer', 'util'], function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var util = layui.util;

            let productId = $("#hfid").val();
            if (productId > 0) {
                $.post("/product/getprice/" + productId, function (resp) {
                    //console.log(resp)
                    if (resp.code == 0) {
                        form.val('productform', resp.data)
                    }
                });
            }
            //form提交事件
            form.on('submit(demo1)', function (data) {
                //console.log(data.field)
                $.post("/product/updateprice", { productData:encodeURIComponent(JSON.stringify(data.field))}, function (resp) {
                    //console.log(1);
                    if (resp.code == 0) {
                        layer.msg('更新成功', { time: 500 }, function () {
                            // 父页面的table重载
                            parent.table.reload('testProduct');
                            // 关闭弹出层
                            var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
                            parent.layer.close(index);
                        });
                    }
                });
                return false;//结束表单
            });
        });
    </script>
</body>
</html>
